home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Macintosh Tracker 1.20 / source / Server⁄Tracker 4.0 / autoinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-01  |  1.1 KB  |  67 lines  |  [TEXT/KAHL]

  1. /* autoinit.c */
  2.  
  3. /* $Id: autoinit.c,v 4.1 1994/01/12 16:10:20 espie Exp espie $ 
  4.  * $Log: autoinit.c,v $
  5.  * Revision 4.1  1994/01/12  16:10:20  espie
  6.  * Fixed up last minute problems.
  7.  *
  8.  * Revision 4.0  1994/01/11  17:41:28  espie
  9.  * *** empty log message ***
  10.  *
  11.  * Revision 1.7  1994/01/09  17:36:22  Espie
  12.  * Generalized open.c.
  13.  *
  14.  * Revision 1.6  1994/01/07  15:06:26  Espie
  15.  * Id
  16.  *
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21.  
  22. #include "defs.h"
  23. #include "extern.h"
  24.  
  25. ID("$Id: autoinit.c,v 4.1 1994/01/12 16:10:20 espie Exp espie $")
  26.  
  27. LOCAL struct clist
  28.     {
  29.     struct clist *next;
  30.     void (*func) P((void));
  31.     } *list = 0;
  32.     
  33.  
  34. void at_end(cleanup)
  35. void (*cleanup) P((void));
  36.     {
  37. #ifdef USE_AT_EXIT
  38.     atexit(cleanup);
  39. #else
  40.     struct clist *new;
  41.     new = (struct clist *)malloc(sizeof(struct clist));
  42.     if (!new)
  43.         {
  44.         (*cleanup)();
  45.         end_all("Allocation problem");
  46.         }
  47.     new->next = list;
  48.     new->func = cleanup;
  49.     list = new;
  50. #endif
  51.     }
  52.     
  53. void end_all(s)
  54. char *s;
  55.     {
  56. #ifndef USE_AT_EXIT
  57.     struct clist *p;
  58. #endif
  59.     if (s)
  60.         notice(s);
  61. #ifndef USE_AT_EXIT
  62.     for (p = list; p; p = p->next)
  63.         (p->func)();            /* don't bother freeing (malloc) */
  64. #endif
  65.     exit(s ? 10 : 0);
  66.     }
  67.